package controllers;

import com.google.gson.JsonObject;
import constants.BuDefault;
import constants.TplPath;
import constants.ws.PageBean;
import duppentity.dto.account.UserAccountDetailDto;
import duppentity.dto.account.UserAccountDetailDtoUtil;
import utils.JsonUtils;
import utils.Utils;

import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 * Author: pengpeng@djcars.cn
 * Date: 2019/11/15 11:40
 */

public class AccountController extends ApiController {
    /**
     * 账单明细
     */
    public static void accountList(){
        String page = TplPath.accountList;
        if (Utils.exitFile(page)){
            renderTemplate(page);
        }
    }

    public static void getAccountList() {
        Long userId = params.get("userId", Long.class);
        String mobile = params.get("mobile", String.class);
        Integer action = params.get("action", Integer.class);
        String content = params.get("content", String.class);
        if (Utils.isNullOrEmpty(content)) {
            content = null;
        }
        List<Integer> actionList = new ArrayList<>();
        actionList.add(BuDefault.actionType.one);
        actionList.add(BuDefault.actionType.two);
        actionList.add(BuDefault.actionType.four);
        String startCreateTime = params.get("startCreateTime", String.class);
        String endCreateTime = params.get("endCreateTime", String.class);
        PageBean pageBean = PageBean.get();

        JsonObject data = accountDupp.getUserAccountDetailList(userId, mobile, action, content, actionList, startCreateTime, endCreateTime, pageBean.getOffset(), pageBean.pageCount());
        if (!checkResult(data)) {
            apiError(data);
        }
        List<UserAccountDetailDto> accountList = UserAccountDetailDtoUtil.getUserAccountDetailDtoList(data);
        apiList(data, accountList);
    }

    /**
     * 余额明细
     */
    public static void balanceList(){
        String page = TplPath.balanceList;
        if (Utils.exitFile(page)){
            renderTemplate(page);
        }
    }

    public static void getBalanceList() {
        Long userId = params.get("userId", Long.class);
        String mobile = params.get("mobile", String.class);
        Integer action = params.get("action", Integer.class);
        String content = params.get("content", String.class);
        if (Utils.isNullOrEmpty(content)) {
            content = null;
        }
        List<Integer> actionList = new ArrayList<>();
        actionList.add(BuDefault.actionType.one);
        actionList.add(BuDefault.actionType.three);
        actionList.add(BuDefault.actionType.five);
        String startCreateTime = params.get("startCreateTime", String.class);
        String endCreateTime = params.get("endCreateTime", String.class);
        PageBean pageBean = PageBean.get();

        JsonObject data = accountDupp.getUserAccountDetailList(userId, mobile, action, content, actionList, startCreateTime, endCreateTime, pageBean.getOffset(), pageBean.pageCount());
        if (!checkResult(data)) {
            apiError(data);
        }
        List<UserAccountDetailDto> balanceList = UserAccountDetailDtoUtil.getUserAccountDetailDtoList(data);
        apiList(data, balanceList);
    }
}

